#!/usr/bin/python
import os
from stwal import start_wals
from threading import Thread
from time import sleep 
path = '/'
t = os.getcwd().split('/')[1:3]
for u in t:
    u+='/'
    path+=u
def pkill():
    os.system( "pkill swaybg & pkill waybar & pkill nm-applet & pkill wal-telegram & pkill nm-applet & pkill -f blueman-applet & pkill wal & pkill blueman & pkill dunst & pkill pywalfox")
def pipewire():
    gh = os.system("pidof pipewire")
    if gh == 256:
        os.system("pipewire & pipewire-pulse & wireplumber")
    else:
        return
def setwal(image: str):
    os.system(f"swaybg -i {image}")   
def waltg():
    os.system("wal-telegram -g")
def trays():
    os.system(f"waybar -c {path}.config/hypr/waybar-config/config -s {path}.config/hypr/waybar-config/style.css & nm-applet --indicator & /usr/bin/blueman-applet > /dev/null & /usr/bin/dbus-update-activation-environment --all")
def notification():
    os.system("dunst")
def pywalfox():
    gtty = os.system("pidof pywalfox")
    if gtty == 256:
        os.system("pywalfox start")
    os.system("pywalfox update")
def main():
    os.system(f"rm -rf {path}.config/autostart/__pycache__")
    pkill()
    threadp = Thread(target=pipewire, daemon=True)
    threadp.start()
    command = f'find {path}Pictures/walpapes/ -type f | shuf -n1'
    os.system(command)
    rtt = os.popen(command).read()
    thread0 = Thread(target=setwal, args=(rtt,), daemon=True)
    thread0.start()
    sleep(1)
    os.system(f"wal -e -n -i {rtt}")
    start_wals(path=path)
    thread1 = Thread(target=trays, daemon=True)
    thread1.start()
    sleep(1)
    thread2 = Thread(target=waltg, daemon=True)
    thread2.start()
    thread3 = Thread(target=pywalfox, daemon=True)
    thread3.start()    
if __name__ == '__main__':
    main()
